package org.ehe.finance.receipt.domain;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.ehe.common.mybatis.core.domain.BaseEntity2;
import org.ehe.finance.receipt.enums.PaymentMethod;
import org.ehe.finance.receipt.enums.ReceiptType;
import org.ehe.finance.receipt.enums.Status;

import java.math.BigDecimal;
import java.time.LocalDate;
import java.util.List;

/**
 * 收款单主表
 * @author :zhangnn
 * @className :ErpFinanceReceipt
 * @description: TODO
 * @date 2025-09-02 14:19:01
 */
@Data
@EqualsAndHashCode(callSuper = true)
@TableName("erp_finance_receipt")
public class ErpFinanceReceipt extends BaseEntity2 {
    /**
     * 收款单ID
     */
    @TableId(type = IdType.AUTO)
    private Long id;

    /**
     * 收款单号
     */
    private String receiptNo;

    /**
     * 客户ID
     */
    private Long customerId;

    /**
     * 收款日期
     */
    private LocalDate receiptDate;

    /**
     * 收款账户ID
     */
    private Long accountId;

    /**
     * 收款总金额
     */
    private BigDecimal totalAmount;

    /**
     * 币种ID
     */
    private Long currencyId;

    /**
     * 汇率
     */
    private BigDecimal exchangeRate;

    /**
     * 收款类型:1销售收款,2预收款,3其他收款
     */
    private Integer receiptType;

    /**
     * 收款方式:1现金,2银行转账,3票据,4其他
     */
    private Integer paymentMethod;

    /**
     * 生成凭证ID
     */
    private Long voucherId;

    /**
     * 部门ID
     */
    private Long departmentId;

    /**
     * 业务员ID
     */
    private Long salesmanId;

    /**
     * 备注
     */
    private String remark;

    /**
     * 状态:1未审核,2已审核
     */
    private Integer status;

    /**
     * 收款明细列表（用于返回数据）
     */
    private List<ErpFinanceReceiptDetail> receiptDetails;

    /**
     * 是否已审核
     */
    public boolean isAudited() {
        return Status.AUDITED.getCode().equals(this.status);
    }

    /**
     * 是否可编辑
     */
    public boolean isEditable() {
        return !isAudited();
    }

    /**
     * 获取收款类型描述
     */
    public String getReceiptTypeDesc() {
        return ReceiptType.getDescByCode(this.receiptType);
    }

    /**
     * 获取收款方式描述
     */
    public String getPaymentMethodDesc() {
        return PaymentMethod.getDescByCode(this.paymentMethod);
    }

    /**
     * 获取状态描述
     */
    public String getStatusDesc() {
        return Status.getDescByCode(this.status);
    }
}
